package com.agent;

import java.io.BufferedReader;
import java.lang.instrument.Instrumentation;
import java.net.MalformedURLException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: fei.wu
 * @Email: fei.wu@rograndec.com
 * @CreateDate: 2019-03-20
 * @Version: 1.0
 */
public class MyAgent {

    public static void premain(String agentArgs, Instrumentation inst) {
        System.out.println("这是一个 agent ; args:" + agentArgs);

        try {
            MyClassLoader classLoader = new MyClassLoader();
            classLoader.loadJar("mph-dubbo-spi-dev-1.0.0-SNAPSHOT.jar");
            Class clz = classLoader.loadClass("mph-dubbo-spi-dev-1.0.0-SNAPSHOT.jar","com.mph.dubbo.Ping");

            clz.getMethod("test").invoke(clz.newInstance(),null);

            Thread.sleep(10000);
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        List<String> k = new ArrayList<>();
        k.add("1");
        k.add("2");
        k.add("3");
        k.add("4");
        k.add("5");
        Iterator<String> iterator = k.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            if (next.equals("3")){
                iterator.remove();
            }
        }
        for (String s : k) {
            System.out.println(s);
        }
    }
}
